package com.bfonseca.pedreiro;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Bitmap.Config;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends Activity {
	private static final int CAMERA_REQUEST = 1888; 
    private ImageView imageView;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        this.imageView = (ImageView)this.findViewById(R.id.imageView1);
        Button photoButton = (Button) this.findViewById(R.id.main_btnFoto);
        photoButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
                startActivityForResult(cameraIntent, CAMERA_REQUEST); 
            }
        });
        
    }
    
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
        if (requestCode == CAMERA_REQUEST) {  
            Bitmap photo = (Bitmap) data.getExtras().get("data"); 
            //imageView.setImageBitmap(photo);
            int w,h;
            w=photo.getWidth();
            h=photo.getHeight();
            
            Paint p = new Paint();
            p.setColor(Color.BLACK);
            p.setTextSize(20);
            
            Bitmap bitmap = Bitmap.createBitmap(w, h, Config.ARGB_8888);
            Canvas c = new Canvas(bitmap);
            c.drawText("oiesilvio",0, 0, p);
            
            Drawable drawable1 = new BitmapDrawable(photo);
            drawable1.setBounds(0, 0, w, h);
            drawable1.draw(c);
            
            
            Canvas canvas = new Canvas(bitmap);
            // new antialised Paint
            Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
            // text color - #3D3D3D
            paint.setColor(Color.BLACK);
            // text size in pixels
            paint.setTextSize((int) (14 * 1));
            // text shadow
            paint.setShadowLayer(1f, 0f, 1f, Color.WHITE);
           
            // draw text to the Canvas center
            Rect bounds = new Rect();
            paint.getTextBounds("Ui adoro", 0, "Ui adoro".length(), bounds);
            int x = (bitmap.getWidth() - bounds.width())/2;
//            int y = (bitmap.getHeight() + bounds.height())/2;
            int y = bounds.height();
           
            canvas.drawText("Ui adoro", x, y, paint);
            
            
            
            
////            
//            /c.drawBitmap(photo, 0, 0, null);
//           / c.drawText("Uiadoro", 0, 0, p);
           
            imageView.setImageBitmap(bitmap);
        }  
    } 
}
